package com.own.component.log.login.core;

import com.alibaba.fastjson2.JSON;
import com.own.component.log.login.entity.LogLoginEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

/**
 * PersistenceLogLoginSpringHook
 *
 * @author chenxueli
 * @date 2023-08-07 22:09:42
 */
@Slf4j
@Component
public class PersistenceLogLoginSpringHook {

    @Resource
    private List<PersistenceLogLoginHook> persistenceLogLoginHookList;

    @PostConstruct
    private void init() {
        var list = persistenceLogLoginHookList.stream().map(item -> item.getClass().getName()).toList();
        log.info("登录日志持久化===>【{}】", JSON.toJSONString(list));
    }

    /**
     * 获取对应的日志操作接口
     *
     * @param entity 登录日志信息
     */
    public void run(LogLoginEntity entity) {

        persistenceLogLoginHookList.forEach(hook -> hook.run(entity));
    }

}
